﻿Chenxin.UI.HouseManage = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: 'service/housemgr.ashx',
    createGrid: function() {
        var _this = this;
        return new Chenxin.UI.ExpandGrid({
            actionUrl: this.actionUrl + '?op=gethouselist',
            autoLoad: false,
            id: 'houselist',
            hasRowNumber: false,
            hasCheckBox: false,
            renderTo: 'house_table',            
            afterRenderTitleTool: function() {
                var _obj = this;
                this.sortCombo = new Chenxin.UI.Combo({
                    containerId: '#xyz',
                    name: 'sortField',
                    defVal: '',
                    defTxt: '默认排序',
                    colNum: 1,
                    colWidth: 105,
                    items: [
						{ txt: '按跟盘时间升序', val: 'servicetime asc', icon: 'x-sort-asc' },
						{ txt: '按跟盘时间降序', val: 'servicetime desc', icon: 'x-sort-desc' },
						{ txt: '按建档时间升序', val: 'adddate asc', icon: 'x-sort-asc' },
						{ txt: '按建档时间降序', val: 'adddate desc', icon: 'x-sort-desc' }
					],
                    onSelected: function() {
                        _obj.sortField = this.getValue();
                        _obj.reload();
                    },
                    afterHeadSelect: function(el) {
                        if (el.f) {
                            this.sortCombo.setVal(this.sortDir.field.toLowerCase() + ' ' + this.sortDir.dir);
                        }
                    }
                });
            },
            createTitleTool: function() {
                return [{
                    text: '<div style="float:left;">排序：</div><div class="SelectWrapSingle" id="xyz" style="z-index:1; margin-top:2px;"></xyz>',
                    showTitle: false
}];
                },
                afterHeadSelect: function(el) {
                    var _sf = this.sortDir.field.toLowerCase() + ' ' + this.sortDir.dir;
                    if (this.sortCombo.findTxtByVal(_sf)) {
                        this.sortCombo.setValue(_sf);
                    } else {
                        this.sortCombo.reset();
                    }
                },
                scope: this,
                rowExpandAble: true,
                rowExpand: function(dom, el, grid) {
                    _this.loadHouseInfo();
                }
            });
        },

        bindBottomBar: function(obj) {
            switch (obj.name) {
                case 'adjourn': //封盘
                    this.showAdjournWin();
                    break;
                case 'task':
                    this.showTaskWin();
                    break;
                case 'performance': //业绩申请
                    if (!this.currentId) {
                        alert('请选择一条房源记录！');
                        return;
                    }
                    var strUrl = $("#ctl00_foot_hidBusinessRoot").val();
                    strUrl = strUrl + "/page/Contract_ApplyInfo/MainBusinessApply.aspx?HouseId=" + this.currentId;
                    window.location.href = strUrl;
                    break;
                case 'collection': //收藏
                    this.collection();
                    break;
                case 'protection': //保护
                    this.showProtectionWin();
                    break;
                case 'unprotection': //保护
                    this.unProtection();
                    break;
                case 'changeconfirmation': //变更确认
                    this.showChangeConfirm();
                    break;
                case 'record': //备案
                    this.showRecordWin();
                    break;
                case 'addContrast': //添加对比
                    this.contrast('add');
                    break;
                case 'removeContrast': //添加对比
                    this.contrast('remove');
                    break;
                case 'view': //加入带看
                    this.addview('remove');
                    break;
                case 'key': //钥匙
                    this.showKeyWin();
                    break;
                case 'intent': //意向金
                    alert('该功能尚未开放！');
                    break;
                case 'report': //报备
                    if (!this.currentId) {
                        alert('请选择一条房源记录！');
                        return;
                    }
                    var strUrl = $("#ctl00_foot_hidBusinessRoot").val();
                    strUrl = strUrl + "/page/Business_Record/ContractArchive.aspx?HouseId=" + this.currentId;
                    window.location.href = strUrl;
                    break;
                case 'commission': //委托
                    this.showCommission();
                    break;
                case 'appPre': //贷款预审
                    if (!this.currentId) {
                        alert('请选择一条房源记录！');
                        return;
                    }
                    var strUrl = $("#ctl00_foot_hidBusinessRoot").val();
                    strUrl = strUrl + "/page/Preliminary_Info/PreliminaryApply.aspx?HouseId=" + this.currentId;
                    window.location.href = strUrl;
                    break;
                case 'sendtoold':
                    this.sendToOld();
                    break;
                case 'edit':
                    if (this.currentHouseInfo) {
                        this.form.permitParam = {
                            model: this.currentHouseInfo.toString()
                        };
                    }
                    this.edit();
                    this.form.setTitle('编辑房源');
                    break;
                case 'uploadHousePic':
                    this.showUploadHousePic();
                    break;
            }
        },
        /**
        *@description 推送给老系统
        */
        sendToOld: function() {
            if (!this.currentId) {
                alert('请选择一条房源记录！');
                return;
            }
            var _this = this;
            Chenxin.Msg.Waiting.show();
            Chenxin.ajax({
                type: "get",
                dataType: "text",
                paramType: 'json',
                url: this.actionUrl,
                data: { op: 'sendtoold', houseid: this.currentId },
                onSuccess: function(data, msg) {
                    Chenxin.Msg.Waiting.hide();
                    alert(msg);
                },
                onFail: function() {
                    Chenxin.Msg.Waiting.hide();
                },
                onWrong: function() {
                    Chenxin.Msg.Waiting.hide();
                },
                onError: function() {
                    Chenxin.Msg.Waiting.hide();
                }
            });
        },
        loadHouseInfo: function() {
            var _this = this;
            Chenxin.ajax({
                type: "get",
                dataType: "text",
                paramType: 'json',
                url: this.actionUrl,
                data: { op: 'gethouseinfo', houseid: this.currentId },
                onSuccess: function(data, msg) {
                    if (data.houseinfo) {
                        _this.currentHouseInfo = data.houseinfo;
                        _this.renderHouseInfo();
                    }
                    _this.createTraceList(data.countTrace);
                }
            });
        },

        renderHouseInfo: function() {
            var m = this.currentHouseInfo;
            var infoStr = '';
            //infoStr += '<d id="tr-house-info" style="height:100px;"><td colspan="11" class="gendan_box" >';
            infoStr += '<div class="houtab fl">';
            infoStr += '<ul class="padding5">';
            infoStr += '<li style="float:left;width:360px;"><b>' + m.Community;
            switch (m.BusinessKind) {
                case 10: //出售
                    var p = (m.SalePrice_T / 10000);

                    infoStr += '&nbsp;&nbsp;<span class="red20">售价：' + p.toFixed(0) + '万</span>';
                    break;
                case 20: //出租
                    infoStr += '&nbsp;&nbsp;<span class="red20">租价：' + m.RentPrice + '元</span>';
                    break;
                case 30: //租售
                    var p = (m.SalePrice_T / 10000);

                    infoStr += '&nbsp;&nbsp;<span class="red20">售价：' + p.toFixed(0) + '万</span>';
                    infoStr += '&nbsp;&nbsp;<span class="red20">租价：' + m.RentPrice + '元</span>';
                    break;
            }

            infoStr += '</b></li>';
            infoStr += '<li style="float:left;width:360px;">地址：' + m.Address + ' ' + ' ' + m.BuildingName + ' ' + m.Room + '</li>';
            infoStr += '<li style="float:left;width:230px;">编号：' + m.HouseCode + '</li>';
            // infoStr += '<li style="float:left;width:110px;">单价：' + Math.round(m.SalePrice_T / m.BuildingArea) + '</li>';
            if (m.BusinessKind != 20) {
                infoStr += '<li style="float:left;width:110px;">单价：' + (m.SalePrice_T / m.BuildingArea).toFixed(0) + '元</li>';
            }
            infoStr += '<li style="float:left;width:230px;">板块：' + m.Block + '</li>';
            infoStr += '<li style="float:left;width:100px;">类型：' + m.BuildingType + '</li>';
            infoStr += '<li style="float:left;width:230px;">建档日期：' + m.Adddate + '</li>';
            infoStr += '<li style="float:left;width:100px;">装修：' + m.Fitment + '</li>';
            infoStr += '<li style="float:left;width:360px;">';
            infoStr += '<div class="btn_pon_3"><a href="ShowDetailInfo.aspx?houseid=' + m.HouseId + '" target="_blank" title="查看详情" >查看详情</a></div>'
            infoStr += '<input name="btn_viewownerinfo" type="button" class="btn_pon_2" value="查看业主信息"/>';
            infoStr += '<input name="btn_trace" type="button" class="btn_pon" value="我要跟单"/>';
            infoStr += '<input name="btn_houseSend" type="button" class="btn_pon" value="房源推送"/>';
            infoStr += '</li>';
            infoStr += '</ul>';
            infoStr += '</div>';
            infoStr += '<div class="gdtab"><div class="outborder">';
            infoStr += '<div class="infos intitss"><span class="rb"><b>跟单内容</b></span><span class="rbpsn"><b>跟单人</b></span><span class="rbtim"><b>跟单时间</b></span></div>';
            infoStr += '<div id="housetrace_table"></div>';
            infoStr += '</div></div>'; //<div id="housetrace_page"></div>
            $('#exp_' + this.currentId).find('dd').append(infoStr);
        },
        createTraceList: function(count) {
            if (!this.tracePage) {
                this.tracePage = new Chenxin.UI.Pagination({
                    id: 'housetrace',
                    renderTo: 'housetrace_table',
                    pageSize: 4,
                    actionUrl: this.actionUrl + '?op=gethousetracelist',
                    data: { houseid: this.currentId }
                });
            } else {
                this.tracePage.recordCount = 0;
                this.tracePage.hasCount = false;
                this.tracePage.reload({ houseid: this.currentId });
            }
        },
        initEvent: function() {
            var _this = this;
            //底部按钮点击事件
            $('.LeftFooter a').click(function() {
                _this.bindBottomBar(this);
				return false;
            });

            //查询菜单点击展开事件
            $(".arrow_1").click(function() {
                $("#panel").slideToggle("slow");
                $(this).toggleClass("up_1");
                return false;
            });

            $("input[name='btn_viewownerinfo']").live('click', function() {
                _this.showCustomerInfo();
            });
            $("input[name='btn_trace']").live('click', function() {
                _this.showTraceWin();
            });

            $("input[name='btn_houseSend']").live('click', function() {
                //_this.showHouseSendWin();
                _this.showHouseSendType();
            });
        },

        /**
        *@description 房源推送----安居客选择匹配房源信息
        */
        showHouseSendWin: function() {
            if (!this.houseSendWin) {
                this.houseSendWin = new Chenxin.UI.HouseSendForm({
                    scope: this,
                    afterGetFormJson: function(json) {
                        this.houseSendWin.additionalParam.HouseSend = json.HouseSend;
                        this.houseSendWin.additionalParam.HouseInfo = this.currentHouseInfo;
                        this.houseSendWin.additionalParam.houseSendtxt_AJK_Tel = this.houseSendtxt_AJK_Tel;
                        this.houseSendWin.additionalParam.txtAJK_Title = this.txtAJK_Title;
                        delete json.HouseSend;
                    }
                });
            }
            this.houseSendWin.show();
            this.houseSendWin.setTitle('安居客房源推送');
            var _data = { CommunityName: this.currentHouseInfo }
            $.ajax({
                type: "post",
                dataType: "json",
                url: "service/SendHouseInfo.ashx?op=Community",
                data: _data,
                success: function(data) {
                    //                if(data.success==0)
                    //                {
                    //                     alert(data.msg);
                    //                     return;
                    //                }
                    var obj = data.community;
                    if (obj == null || obj == "undefined") {
                        $('#td_showHouseInfo').html(data.message + "，建议去安居客手工发布！！！");
                        return;
                    }
                    var text = '';
                    for (var i = 0; i < obj.length; i++) {
                        text += '<input type="radio"  name="HouseSend" groupname value="' + obj[i].commId + '" /><span title="' + obj[i].areaString + ',' + obj[i].subAreaString + ',' + obj[i].location + '">' + obj[i].name + '</span>&nbsp;';
                    }
                    // text+='<input type="hidden" id="hdnSaveObj" value="'+ this.currentHouseInfo+'" />';
                    $('#td_showHouseInfo').html(text);
                }
            });
        },

        /**
        *@description 选择推送房源的网站 (安居客,房友在线)
        */
        showHouseSendType: function() {
            if (!this.houseSendTypeWin) {
                this.houseSendTypeWin = new Chenxin.UI.HouseSendType({
                    scope: this,
                    initEvent: function() {
                        var _this = this;
                        $('#houseSend_AJK').live('click', function() {
                            _this.hide();
                            _this.scope.showHouseSendTypeAJK_Tel();
                            $('#td_showHouseInfo').html("正在查找类似房源……");
                        }),
				            $('#houseSend_CityReHouse').live('click', function() {
				                //                        _this.additionalParam.CityReHouseHouseInfo=_this.scope.currentHouseInfo;
				                //                        _this.op="CityReHouse_Add";
				                //                        _this.save();
				                _this.hide();
				                _this.scope.showHouseSendCityReHouse();
				            }),
				            $('#houseSend_FYZX').live('click', function() {
				                _this.hide();
				                _this.scope.showHouseSendSina();
				            });
				            $('#houseSend_SouFun').live('click', function() {
				                _this.hide();
				                _this.scope.showHouseSendSouFun();
				            });
                    }
                });
            }
            this.houseSendTypeWin.show();
            this.houseSendTypeWin.setTitle('选择房源推送目标');
        },

        /**
        *@description  安居客推送房源-----输入安居客经纪人手机号码
        */
        showHouseSendTypeAJK_Tel: function() {
            if (!this.houseSendTypeAJKWin) {
                this.houseSendTypeAJKWin = new Chenxin.UI.HouseSendAJK_Tel({
                    scope: this,
                    initEvent: function() {
                        var _this = this;
                        $('#houseSend_AJK_Tel').live('click', function() {
                            var _value = _this.findByName('houseSendtxt_AJK_Tel').val();
                            var _AJK_House_Title = $("#txtAJK_Title").val();
                            if (!_value) {
                                alert('请输入手机号码');
                                return;
                            }
                            else {
                                var myreg = /^(?:13\d|15[89])-?\d{5}(\d{3}|\*{3})$/;
                                if (isNaN(parseInt(_value)) || _value.length != 11) {
                                    alert("请输入合法的手机号码");
                                    return;
                                }
                            }
                            if (!_AJK_House_Title) {
                                alert("请输入房源标题");
                                return;
                            }
                            _this.scope.houseSendtxt_AJK_Tel = _value;
                            _this.scope.txtAJK_Title = _AJK_House_Title;
                            _this.hide();
                            _this.scope.showHouseSendWin();
                        });
                    }
                });
            }
            this.houseSendTypeAJKWin.show();
            this.houseSendTypeAJKWin.setTitle('确认安居客电话');
        },

        /**
        *@description  房源推送------新浪房友在线
        */
        showHouseSendSina: function() {
            if (!this.houseSendSinaWin) {
                this.houseSendSinaWin = new Chenxin.UI.HouseSendSina_UserId({
                    scope: this,
                    afterGetFormJson: function(json) {
                        this.houseSendSinaWin.additionalParam.SinaUserId = json.houseSendtxt_Sina_UserId;
                        this.houseSendSinaWin.additionalParam.SinaHouseTitle = json.txtSina_Title;
                        this.houseSendSinaWin.additionalParam.SinaHouseInfo = this.currentHouseInfo;
                        delete json.houseSendtxt_Sina_UserId;
                        delete json.txtSina_Title;
                    }
                });

            }
            this.houseSendSinaWin.op = "Sina_Add";
            this.houseSendSinaWin.show();
            this.houseSendSinaWin.setTitle('推送房友在线');
        },
        
        
                /**
        *@description  房源推送------搜房网
        */
        showHouseSendSouFun: function() {
            if (!this.houseSendSouFunWin) {
                this.houseSendSouFunWin = new Chenxin.UI.HouseSendSouFun_UserInfo({
                    scope: this,
                    afterGetFormJson: function(json) {
                        this.houseSendSouFunWin.additionalParam.SouFunUserId = json.houseSendtxt_SouFun_UserId;
                        this.houseSendSouFunWin.additionalParam.SouFunUserPwd = json.houseSendtxt_SouFun_UserPwd;
                        this.houseSendSouFunWin.additionalParam.SouFunHouseTitle = json.txtSouFun_Title;
                        this.houseSendSouFunWin.additionalParam.SouFunHouseInfo = this.currentHouseInfo;
                        delete json.houseSendtxt_SouFun_UserId;
                        delete json.houseSendtxt_SouFun_UserPwd;
                        delete json.txtSina_Title;
                    }
                });

            }
            this.houseSendSouFunWin.op = "SouFun_Add";
            this.houseSendSouFunWin.show();
            this.houseSendSouFunWin.setTitle('推送搜房帮');
        },


        /**
        *@description  房源推送------CityReHouse
        */
        showHouseSendCityReHouse: function() {
            if (!this.houseSendCityReHouseWin) {
                this.houseSendCityReHouseWin = new Chenxin.UI.HouseSendCityReHouse({
                    scope: this,
                    afterGetFormJson: function(json) {

                        this.houseSendCityReHouseWin.additionalParam.CityReHouseUserId = json.houseSendtxt_CityReHouse;
                        this.houseSendCityReHouseWin.additionalParam.CityReHouseHousePwd = json.txtpwd_CityReHouse;
                        if (json.selectKeyWord != undefined && json.selectKeyWord != "请选择") {
                            this.houseSendCityReHouseWin.additionalParam.CityReHouseHouseTitle = json.txtCityReHouse_Title + "   " + json.selectKeyWord;
                        }
                        else {
                            this.houseSendCityReHouseWin.additionalParam.CityReHouseHouseTitle = json.txtCityReHouse_Title;
                        }
                        this.houseSendCityReHouseWin.additionalParam.CityReHouseHouseInfo = this.currentHouseInfo;
                        delete json.houseSendtxt_CityReHouse;
                        delete json.txtCityReHouse_Title;
                    }
                });

            }
            this.houseSendCityReHouseWin.op = "CityReHouse_Add";
            this.houseSendCityReHouseWin.show();
            this.houseSendCityReHouseWin.setTitle('推送CityReHouse');
        },

        showCustomerInfo: function() {
            var _this = this;
            if (!this.HouseCustomerForm) {
                this.HouseCustomerForm = new Chenxin.UI.HouseCustomerForm({
                    alwaysCheckPermit: true,
                    op: 'edit',
                    scope: this,
                    beforeFitData: function(model) {
                        _this.HouseCustomerForm.currentHouseInfo = _this.currentHouseInfo;
                    }
                });
            }
            if (this.HouseCustomerForm.show('view', { currentId: this.currentHouseInfo.CustomerId })) {
                this.getModel(this.currentHouseInfo.HouseId, this.HouseCustomerForm.fitData, this.HouseCustomerForm, 'service/CustomerMgr.ashx', 'getmodel', { flg: 'house' });
                this.HouseCustomerForm.setTitle('查看业主信息');
            }
        },
        /**
        *@description 收藏
        */
        collection: function() {
            if (this.currentId && this.currentHouseInfo) {
                Chenxin.ajax({
                    type: "post",
                    url: "service/favorite.ashx?op=add",
                    data: {
                        houseid: this.currentId,
                        houseaddress: this.currentHouseInfo.Community + ' ' + this.currentHouseInfo.BuildingName + ' ' + this.currentHouseInfo.Room
                    },
                    dataType: "text",
                    onSuccess: function(data, msg) {
                        alert(msg);
                    }
                });

            } else {
                alert('请先选择一条记录！');
            }
        },
        /**
        *@description 委托
        */
        showCommission: function() {
            if (!this.currentId) {
                alert('请先选择一条房源记录！');
                return;
            }

            if (!this.commissionWin) {
                var _this = this;
                this.commissionWin = new Chenxin.UI.CommissionForm({
                    currentId: this.currentId,
                    alwaysCheckPermit: true,
                    afterGetFormJson: function(json) {
                        json.HouseId = _this.currentHouseInfo.HouseId;
                        json.Employee = this.employeeId.getText();
                        json.EmpDepart = this.empDepartId.getText();
                        json.EntrustCode = "wt" + json.EntrustCode;
                    }
                });
            }

            if (this.commissionWin.show(this.op, { model: this.currentHouseInfo })) {
                this.commissionWin.fitData({
                    HouseCode: this.currentHouseInfo.HouseCode,
                    HouseAddress: this.currentHouseInfo.Community + this.currentHouseInfo.BuildingName + this.currentHouseInfo.Room
                })
                this.commissionWin.currentId = this.currentId;
            }
        },

        /**
        *@description 封盘
        */
        showAdjournWin: function() {
            if (!this.currentId) {
                alert('请先选择一条房源记录！');
                return;
            }

            var _this = this;
            if (!this.adjournWin) {
                this.adjournWin = new Chenxin.UI.AdjournForm({
                    currentId: this.currentId,
                    alwaysCheckPermit: true,
                    afterGetFormJson: function(json) {
                        if (this.op == 'add') {
                            json.HouseId = _this.currentHouseInfo.HouseId;
                            this.additionalParam.workcode = json.workcode;
                            delete json.workcode;
                            delete json.Asker;
                            delete json.AskerDepart;
                            delete json.AddPerson;
                            delete json.AddDepart;
                            json.HouseAddress = json.Address;
                            delete json.Address;
                        } else {

                            Chenxin.apply(json, this.currentModel);
                            this.additionalParam = {};
                        }
                    }
                });
            }
            if (this.adjournWin.show(_this.op, { model: this.currentHouseInfo })) {
                if (this.currentHouseInfo.Status == 30) {//已经封盘，执行解盘			
                    Chenxin.ajax({
                        type: "post",
                        dataType: "json",
                        url: 'service/LockedHandler.ashx',
                        data: { op: 'getmodel', modelid: _this.currentId },
                        scope: this,
                        onSuccess: function(data) {
                            this.adjournWin.reset();
                            this.adjournWin.currentModel = data;
                            this.adjournWin.fitData(data);
                        }
                    });
                    this.adjournWin.setTitle('解除封盘');
                    this.adjournWin.op = 'unlock';
                    $('#adjourn_Save span').text('解盘');
                } else {
                    this.adjournWin.reset();
                    this.adjournWin.setTitle('登记封盘');

                    var _data = {};
                    Chenxin.apply(_data, this.currentHouseInfo);
                    _data.AddPerson = this.currentHouseInfo.OprPerson;
                    _data.AddDepart = this.currentHouseInfo.OprDepart;
                    _data.Remarks = '';
                    _data.Address = this.currentHouseInfo.Community + this.currentHouseInfo.BuildingName + this.currentHouseInfo.Room;
                    this.adjournWin.fitData(_data);
                    $('#adjourn_Save span').text('封盘');
                }

                this.adjournWin.currentId = this.currentId;
            }
        },

        /**
        *创建表单
        */
        createForm: function() {
            return new Chenxin.UI.HouseBaseInfoForm({
                scope: this,
                autoInit: true,
                saveSucc: function() {
                    this.reloadGrid();
                }
            });
        },

        /**
        *@description 取消保护
        */
        unProtection: function() {
            if (!this.currentId) {
                alert('请先选择一条房源记录！');
                return;
            }
            this.del('unprotection', '确定取消这条房源记录的电话保护吗？', "service/protectPhoneHandler.ashx");
        },
        /**
        *@description 店长保护
        */
        showProtectionWin: function() {
            if (!this.currentId) {
                alert('请先选择一条房源记录！');
                return;
            }
            var _this = this;
            if (!this.protectionWin) {

                this.protectionWin = new Chenxin.UI.ProtectionForm({
                    currentId: this.currentId,
                    title: '店长保护',
                    alwaysCheckPermit: true,
                    afterGetFormJson: function(json) {
                        delete json.HouseCode;
                        delete json.Address;
                        delete json.AddPerson;
                        delete json.AddDepart;
                        json.HouseId = _this.currentId;
                        Chenxin.apply(_this.currentHouseInfo, json);
                    },
                    saveSucc: function() {//提交成功
                        _this.currentHouseInfo.IsProtectPhone = true;
                        _this.reloadGrid();
                    },
                    saveFail: function() {//提交失败
                        _this.currentHouseInfo.DisplayPhone = '';
                    }
                });
            }
            this.protectionWin.op = 'protection';
            if (this.protectionWin.show(_this.op, { model: this.currentHouseInfo })) {
                //var _data = this.currentHouseInfo;
                var _data = {};
                Chenxin.apply(_data, this.currentHouseInfo);
                _data.AddPerson = this.currentHouseInfo.OprPerson;
                _data.AddDepart = this.currentHouseInfo.OprDepart;
                _data.Address = this.currentHouseInfo.Community + this.currentHouseInfo.BuildingName + this.currentHouseInfo.Room;
                _data.DisplayPhone = '';
                this.protectionWin.fitData(_data);
                this.protectionWin.currentId = this.currentId;
            }
        },

        /**
        *@description 请求变更/变更确认
        */
        showChangeConfirm: function() {
            var _this = this;
            if (!this.currentId) {
                alert('请先选择一条房源记录！');
                return;
            }
            if (!this.changeConfirmWin) {
                this.changeConfirmWin = new Chenxin.UI.ChangeConfirmationForm({
                    currentId: this.currentId,
                    scope: this,
                    afterGetFormJson: function(json) {
                        delete json.AddPerson
                        delete json.AddDepart
                        delete json.Address;
                        delete json.nowStatus;
                        if (this.changeConfirmWin.requestUser) {
                            json.RequestUserId = this.changeConfirmWin.requestUser.UserId;
                            json.RequestDepartId = this.changeConfirmWin.requestUser.DepartId;
                            json.RequestUserCode = this.changeConfirmWin.requestUser.UserCode;
                        }
                        if (json.ChangeType == '10') {//状态变更，无需传递此参数
                            if (json.RequestDepartId) {
                                delete json.RequestDepartId;
                            }
                            if (json.RequestUserId) {
                                delete json.RequestUserId;
                            }
                            if (json.RequestDepart) {
                                delete json.RequestDepart;
                            }
                            if (json.RequestUser) {
                                delete json.RequestUser;
                            }
                            if (json.RequestUserCode) {
                                delete json.RequestUserCode;
                            }
                        } else if (json.ChangeType == '20') {//人员变更，无需传递此参数	
                            if (json.HouseStatus) {
                                delete json.HouseStatus;
                            }
                        }
                        json.Mobile = json.request_customerMoblie;
                        json.Phone = json.request_customerPhone;
                        json.CustomerName = json.request_customerName;
                        delete json.request_customerName
                        delete json.request_customerPhone
                        delete json.request_customerMoblie

                        json.HouseId = _this.currentId;
                    }
                });
            }
            if (this.changeConfirmWin.show()) {

                this.changeConfirmWin.setTitle('请求变更');
                //var _data = this.currentHouseInfo;
                var _data = {};
                Chenxin.apply(_data, this.currentHouseInfo);
                _data.Remarks = '';
                var temp = this.currentHouseInfo.Status;
                if (temp == 10)
                    temp = '有效';
                else if (temp == 20)
                    temp = '暂缓';
                else if (temp == -1)
                    temp = '无效';
                else if (temp == 30)
                    temp = '封盘';
                else
                    temp = '';
                _data.nowStatus = temp;
                _data.AddPerson = this.currentHouseInfo.OprPerson;
                _data.AddDepart = this.currentHouseInfo.OprDepart;
                _data.Address = this.currentHouseInfo.Community + this.currentHouseInfo.BuildingName + this.currentHouseInfo.Room;
                this.changeConfirmWin.fitData(_data);
                $("#request_tr1").show();
                $("#request_tr2").hide();
                $("#request_tr3").hide();
                $("#request_tr4").hide();
                $("#request_tr5").hide();
                $("#request_tr6").hide();
                $("#request_tr7").hide();
                //delete this.currentHouseInfo.nowStatus;
                this.changeConfirmWin.currentId = this.currentId;
            }
        },

        /**
        *@description 添加/移除对比
        */
        contrast: function(op) {
            var message = '';
            if (op == 'add') {
                message = '确定要添加对比吗？';
            } else {
                message = '确定要删除对比吗？';
            }
            if (!confirm(message)) {
                return;
            }

            if (this.currentId) {
                var data = {
                    op: op || 'add',
                    houseid: this.currentId
                }
                Chenxin.ajax({
                    type: "get",
                    url: "service/compareHouse.ashx",
                    data: data,
                    dataType: "json",
                    onSuccess: function(data, msg) {
                        alert(msg);
                    }
                });
            } else {
                alert('请先选择一条记录！');
            }
        },
        /**
        *@description 加入带看
        */
        addview: function() {
            var _this = this;
            if (!this.currentId) {
                alert('请先选择一条房源记录！');
                return;
            }
            Chenxin.ajax({
                type: "get",
                url: "service/viewHouse.ashx",
                data: { op: 'addcache', houseid: this.currentId },
                dataType: "json",
                onSuccess: function(data, msg) {
                    alert(msg);
                }
            });
        },
        /**
        *@description 备案
        */
        showRecordWin: function() {
            var _this = this;
            if (!this.currentId) {
                alert('请先选择一条房源记录！');
                return;
            }

            if (!this.recordWin) {
                this.recordWin = new Chenxin.UI.RecordForm({
                    currentId: this.currentId,
                    alwaysCheckPermit: true,
                    afterGetFormJson: function(json) {
                        delete json.AddPerson;
                        delete json.AddDepart;
                        json.HouseAddress = json.Address;
                        delete json.Address;
                        delete json.HouseCode;
                        json.HouseId = _this.currentHouseInfo.HouseId;
                    }
                });
            }
            if (this.recordWin.show(_this.op, { model: this.currentHouseInfo })) {
                //var _data = this.currentHouseInfo;
                var _data = {};
                Chenxin.apply(_data, this.currentHouseInfo);
                _data.AddPerson = this.currentHouseInfo.OprPerson;
                _data.AddDepart = this.currentHouseInfo.OprDepart;
                _data.MarkCode = '';
                _data.Address = this.currentHouseInfo.Community + this.currentHouseInfo.BuildingName + this.currentHouseInfo.Room;
                this.recordWin.fitData(_data);
                this.recordWin.setTitle('添加备案');
                this.recordWin.currentId = this.currentId;
            }
        },

        /**
        *@description 钥匙
        */
        showKeyWin: function() {

            var _this = this;
            if (!this.currentId) {
                alert('请先选择一条房源记录！');
                return;
            }
            if (!this.keyWin) {
                this.keyWin = new Chenxin.UI.KeyForm({
                    currentId: this.currentId,
                    alwaysCheckPermit: true,
                    afterGetFormJson: function(json) {
                        delete json.AddPerson;
                        delete json.AddDepart;
                        json.HouseAddress = json.Address;
                        delete json.Address;
                        json.HouseId = _this.currentHouseInfo.HouseId;
                    }
                });
            }
            if (this.keyWin.show(_this.op, { model: this.currentHouseInfo })) {
                //var _data = this.currentHouseInfo;
                var _data = {};
                Chenxin.apply(_data, this.currentHouseInfo);
                _data.AddPerson = this.currentHouseInfo.OprPerson;
                _data.AddDepart = this.currentHouseInfo.OprDepart;
                _data.Address = this.currentHouseInfo.Community + this.currentHouseInfo.BuildingName + this.currentHouseInfo.Room;
                this.keyWin.fitData(_data);
                this.keyWin.setTitle('钥匙收据登记');
                this.keyWin.currentId = this.currentId;
            }
        },

        /**
        *@description 跟单
        */
        showTraceWin: function() {
            var _this = this;
            if (!this.traceWin) {
                this.traceWin = new Chenxin.UI.TraceForm({
                    afterGetFormJson: function(json) {
                        delete json.AddPerson;
                        delete json.AddDepart;
                        json.HouseAddress = json.Address;
                        json.HouseId = _this.currentId;
                        delete json.Address;

                        if (this.isNotice) {
                            this.additionalParam.noticemodel = {
                                body: json.body,
                                NoticeTime: json.SendDate,
                                HouseId: _this.currentId,
                                HouseAddress: _this.currentHouseInfo.Community + _this.currentHouseInfo.BuildingName + _this.currentHouseInfo.Room
                            };
                            delete json.body;
                            delete json.SendDate;
                        } else {
                            this.additionalParam = {};
                        }
                        this.additionalParam.isnotice = json.isnotice || '0';
                        delete json.isnotice;
                    }
                });
            }
            if (this.traceWin.show()) {
                $('#tr_noticetime').hide();
                $('#tr_noticecontent').hide();

                //var _data = this.currentHouseInfo;
                var _data = {};
                Chenxin.apply(_data, this.currentHouseInfo);
                _data.Address = this.currentHouseInfo.Community + this.currentHouseInfo.BuildingName + this.currentHouseInfo.Room;
                _data.AddPerson = this.currentHouseInfo.OprPerson;
                _data.AddDepart = this.currentHouseInfo.OprDepart;
                this.traceWin.fitData(_data);
                this.traceWin.setTitle('房源跟单');
            }
        },

        /**
        *@description 任务分配
        */
        showTaskWin: function() {
            var _this = this;
            if (!this.currentId) {
                alert('请先选择一条房源记录！');
                return;
            }

            if (!this.taskWin) {
                this.taskWin = new Chenxin.UI.TaskForm({
                    alwaysCheckPermit: true,
                    afterGetFormJson: function(json) {
                        json.relatedId = _this.currentHouseInfo.HouseId;
                    }
                });
            }
            if (this.taskWin.show(this.op, { model: this.currentHouseInfo })) {
                //var _data = this.currentHouseInfo;
                var _data = {};
                Chenxin.apply(_data, this.currentHouseInfo);
                _data.AddPerson = this.currentHouseInfo.OprPerson;
                _data.AddDepart = this.currentHouseInfo.OprDepart;
                _data.relatedCode = this.currentHouseInfo.HouseCode;
                _data.relatedCaption = this.currentHouseInfo.Community + this.currentHouseInfo.BuildingName + this.currentHouseInfo.Room;
                this.taskWin.fitData(_data);
                //this.taskWin.fitData(this.currentHouseInfo);
            }
        },

        /**
        *@房源图上传
        */
        showUploadHousePic: function() {
            if (!this.currentId) {
                alert('请先选择一条房源记录！');
                return;
            }
            if (!this.showUploadHousePicWin) {
                var _this = this;
                this.showUploadHousePicWin = new Chenxin.UI.UploadHousePicWin({
                    scope: this,
                    title: '上传房源图片'
                });
            }
            if (this.showUploadHousePicWin.show()) {
                this.FillHousePic(this.currentId);
            }
        },

        createSearch: function() {
            return new Chenxin.UI.HouseManageSearch({
                scope: this
            });
        },
        /**
        *@房源图上传——填充图片预览
        */
        FillHousePic: function(houseid) {
            for (i = 0; i < $('input[name="cbxPicId"]').length; i++) {
                $('input[name="cbxPicId"]')[i].checked = false;
                $('input[name="cbxPicId"]')[i].value = "";
            }
            $("#img_house_1").attr("src", "images/noimage.gif");
            $('#img_house_2').attr("src", "images/noimage.gif");
            $('#img_house_3').attr("src", "images/noimage.gif");
            $('#img_inside_1').attr("src", "images/noimage.gif");
            $('#img_inside_2').attr("src", "images/noimage.gif");
            $('#img_inside_3').attr("src", "images/noimage.gif");
            $('#img_outside_1').attr("src", "images/noimage.gif");
            $('#img_outside_2').attr("src", "images/noimage.gif");
            $('#img_outside_3').attr("src", "images/noimage.gif");
            Chenxin.ajax({
                type: "post",
                dataType: "json",
                url: "service/UploadHousePic.ashx?GetAllPic=" + houseid,
                onSuccess: function(data) {
                    for (var i = 0; i < data.rows.length; i++) {
                        if (data.rows[i].PicType == "房型图") {
                            if ($("#img_house_1").attr("src") == "images/noimage.gif") {
                                $("#img_house_1").attr("src", data.rows[i].ThumbnailUrl);
                                $('#cbx_house_1').val(data.rows[i].RecordId);
                            }
                            else if ($('#img_house_2').attr("src") == "images/noimage.gif") {
                                $('#img_house_2').attr("src", data.rows[i].ThumbnailUrl);
                                $('#cbx_house_2').val(data.rows[i].RecordId);
                            }
                            else if ($('#img_house_3').attr("src") == "images/noimage.gif") {
                                $('#img_house_3').attr("src", data.rows[i].ThumbnailUrl);
                                $('#cbx_house_3').val(data.rows[i].RecordId);
                            }
                        }
                        else if (data.rows[i].PicType == "室内图") {
                            if ($('#img_inside_1').attr("src") == "images/noimage.gif") {
                                $('#img_inside_1').attr("src", data.rows[i].ThumbnailUrl);
                                $('#cbx_inside_1').val(data.rows[i].RecordId);
                            }
                            else if ($('#img_inside_2').attr("src") == "images/noimage.gif") {
                                $('#img_inside_2').attr("src", data.rows[i].ThumbnailUrl);
                                $('#cbx_inside_2').val(data.rows[i].RecordId);
                            }
                            else if ($('#img_inside_3').attr("src") == "images/noimage.gif") {
                                $('#img_inside_3').attr("src", data.rows[i].ThumbnailUrl);
                                $('#cbx_inside_3').val(data.rows[i].RecordId);
                            }
                        }
                        else if (data.rows[i].PicType == "室外图") {
                            if ($('#img_outside_1').attr("src") == "images/noimage.gif") {
                                $('#img_outside_1').attr("src", data.rows[i].ThumbnailUrl);
                                $('#cbx_outside_1').val(data.rows[i].RecordId);
                            }
                            else if ($('#img_outside_2').attr("src") == "images/noimage.gif") {
                                $('#img_outside_2').attr("src", data.rows[i].ThumbnailUrl);
                                $('#cbx_outside_2').val(data.rows[i].RecordId);
                            }
                            else if ($('#img_outside_3').attr("src") == "images/noimage.gif") {
                                $('#img_outside_3').attr("src", data.rows[i].ThumbnailUrl);
                                $('#cbx_outside_3').val(data.rows[i].RecordId);
                            }
                        }
                    }
                }
            });
        },
        initComponent: function() {
            Chenxin.UI.HouseManage.superclass.initComponent.call(this);
            this.reloadGrid();
        }
    });

/**
*查询面板
*/
Chenxin.UI.HouseManageSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'house_search',
    initEvent: function() {
        var _this = this;
        $('#btn_search').click(function() {
            _this.scope.reloadGrid();
        });

        $('.a-qucik-search').click(function() {
            var sm = _this.getParamJson();
            sm.quicktype = this.id;
            _this.scope.grid.reload(sm);
            $(".menu_list").hide(1, function() { $(this).parent(".tlBtn").removeClass("click") });
        });

        $("#resetbutton").live('click', function() {
            $("#daybegin").val("");
            $("#dayend").val("");
            _this.reset();
			_this.daytype.setValue('20');
			_this.priceType.setValue('t_price');
			
			$('#lowprice').defText({
				deftxt: '单位:万'
			})
			$('#heightprice').defText({
				deftxt: '单位:万'
			})
			
        });

        //小区自动填充
        $('#txtHousing').autocomplete({
            deferRequestBy: 5,
            width: 200,
            serviceUrl: this.scope.actionUrl + '?op=loadcommunity'
        });
        $('#txtHousing').defText({
            deftxt: '输入楼盘名称'
        });
        $('#txt_bname').defText({
            deftxt: '输入栋号'
        })
        $('#txt_room').defText({
            deftxt: '输入室'
        })
        $('#keyword').defText({
            deftxt: '输入地址/编号/楼盘'
        })
        $('#txt_usercode').defText({
            deftxt: '输入工号'
        })
        $('#lowprice').defText({
            deftxt: '单位:万'
        });
        $('#heightprice').defText({
            deftxt: '单位:万'
        });
		$('#lowprice').numberText({
			minValue:0
		});
		$('#heightprice').numberText({
			minValue:0
		});
		$('#floor_start').numberText({
			minValue:0
		});
		$('#floor_end').numberText({
			minValue:0
		});
		
		$('#area_start').numberText({
			minValue:0
		});
		$('#area_end').numberText({
			minValue:0
		});
		
        $('#customer_tel').defText({
            deftxt: '业主电话'
        });

    },
    createComboList: function() {
        
		/*var region = new Chenxin.UI.ParameterCombo({
            name: 'region',
            containerId: '#region',
            key: 'System.Region',
            tbxWidth: 45,
            inModelType: 'txt',
            param: { filter: 'bycity' },
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    block.clearItems();
                } else {
                    block.param.subkey = this.getValue();
                    block.param.recordid = this.getValueRecord()['id'];
                    block.reload();
                }
            }
        });
        var block = new Chenxin.UI.ParameterCombo({
            containerId: '#block',
            key: 'System.Block',
            tbxWidth: 45,
            colWidth: 90,
            inModelType: 'txt',
            autoLoad: false
        });*/
		
		var _wc=new Chenxin.UI.RegionBlockWinCombo({
			containerId:'div_region_block'
		});
		
        var status = new Chenxin.UI.Combo({
            containerId: '#status',
            tbxWidth: 45,
			addPleaseSelected:false,
            items: comboCommon.houseStatus2
        });
        var business = new Chenxin.UI.Combo({
            containerId: '#business',
            tbxWidth: 45,
            items: comboCommon.houseBusiness
        });
        var houseuse = new Chenxin.UI.ParameterCombo({
            containerId: '#houseuse',
            key: 'House.Use',
            autoLoad: true,
            tbxWidth: 45,
            inModelType: 'txt',
            paramType: 'text'
        });
        var buildingtype = new Chenxin.UI.ParameterCombo({
            containerId: '#buildingtype',
            key: 'Building.Type',
            autoLoad: true,
            tbxWidth: 90,
            inModelType: 'txt',
            paramType: 'text'
        });


        //装修程度
        var fitment = new Chenxin.UI.ParameterCombo({
            containerId: '#div_fitment',
            name: 'Fitment',
            key: 'House.Fitment',
            inModelType: 'txt',
            tbxWidth: 45
        });

        this.daytype = new Chenxin.UI.Combo({
            containerId: '#daytype',
            initValue: '20',
            tbxWidth: 45,
            colNum: 1,
            addPleaseSelected: false,
            items: comboCommon.dateType
        });

        var markStatus = new Chenxin.UI.Combo({
            containerId: '#marked',
            tbxWidth: 45,
            items: comboCommon.MarkStatus
        });

        var protectedStatus = new Chenxin.UI.Combo({
            containerId: '#protected',
            tbxWidth: 45,
            items: comboCommon.ProtectedStatus
        });


        this.priceType = new Chenxin.UI.Combo({
            containerId: '#price_type',
            tbxWidth: 45,
            colNum: 1,
            name: 'pricetype',
            initValue: 't_price',
            addPleaseSelected: false,
            items: [{ txt: '总价', val: 't_price' }, { txt: '单价', val: 'u_price'}],
            onSelected: function() {
                if (this.getValue() == 't_price') {
                    $('#lowprice').defText({
                        deftxt: '单位:万'
                    })
                    $('#heightprice').defText({
                        deftxt: '单位:万'
                    })
                } else { 
                  $('#lowprice').defText({
                        deftxt: '单位:元'
                    })
                    $('#heightprice').defText({
                        deftxt: '单位:元'
                    })
                }
            }
        });


        var key = new Chenxin.UI.Combo({
            containerId: '#div_key',
            tbxWidth: 45,
            colNum: 1,
            name: 'haskey',
            items: [{ txt: '有', val: '10' }, { txt: '无', val: '0'}]
        });

        var hall = new Chenxin.UI.Combo({
            containerId: '#div_hall',
            tbxWidth: 24,
            colNum: 1,
			showMode:'multi',
            name: 'househall',
            defTxt: '厅',
            items: [{ txt: '1厅', val: '1' }, { txt: '2厅', val: '2' }, { txt: '3厅', val: '3' }, { txt: '4厅', val: '4' }, { txt: '5厅', val: '5'}]
        });

        var room = new Chenxin.UI.Combo({
            containerId: '#div_room',
            tbxWidth: 24,
            name: 'houseroom',
			showMode:'multi',
            colNum: 1,
            defTxt: '室',
            items: [{ txt: '1室', val: '1' }, { txt: '2室', val: '2' }, { txt: '3室', val: '3' }, { txt: '4室', val: '4' }, { txt: '5室', val: '5'}]
        });



        var combl = new Chenxin.UI.StructComboList({
            cityAfterSelected: function(val) {
                
				/*if (val == combl.city.defVal) {
                    region.clearItems();
                } else {
                    region.param.cityid = val;
                    region.reload();
                }
                block.clearItems();*/
				_wc.reload({cityid:val});
            }
        });
        var structs = combl.comboList;
        // structs.push(region);
        // structs.push(block);
		structs.push(_wc);
        structs.push(status);
        structs.push(business);
        structs.push(houseuse);
        structs.push(buildingtype);
        structs.push(this.daytype);
        structs.push(markStatus);
        structs.push(protectedStatus);
        structs.push(this.priceType);
        structs.push(key);
        structs.push(hall);
        structs.push(room);
        structs.push(fitment);

        return structs;
    },
    initComponent: function() {
        Chenxin.UI.HouseManageSearch.superclass.initComponent.call(this);
    }
});

dataKeyList='System.Toward,House.Use,House.Property,House.Source,House.Paymode,House.Actuality,House.Fitment,Building.Type'

function setunitprice(){
	if($('#wtjzmj').val()&&$('#wtfwzj').val())
	{
		$('#wtfwdj').val(parseFloat($('#wtfwzj').val())/parseFloat($('#wtjzmj').val()));
	}
}

































































